package br.com.appcalipse.pages.anuncio;

import java.util.List;

import jmine.tec.report.impl.table.ReportTableBuilder;
import jmine.tec.web.wicket.component.report.AbstractComponentValueResolver;
import jmine.tec.web.wicket.pages.form.CrudModelPage;
import jmine.tec.web.wicket.pages.form.FormType;

import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import bancosys.tec.exception.MessageCreator;
import bancosys.tec.persist.dao.BaseDAOFactory;
import br.com.appcalipse.dao.AnuncioDAO;
import br.com.appcalipse.domain.Anuncio;

/**
 * Tela de pesquisa para cadastro de anuncios.
 *  
 * @author finx
 * @created apr 25, 2013
 */
public class PesquisaAnuncio extends CrudModelPage<AnuncioFilter, Anuncio> {


    /**
     * {@inheritDoc}
     */
    public Page createNewPage() {
        return new CadastroAnuncio(new PageParameters(), this);
    }

    /**
     * {@inheritDoc}
     */
    public List<Anuncio> search(BaseDAOFactory daoFactory) {
        AnuncioDAO dao = daoFactory.getDAOByClass(AnuncioDAO.class);
        AnuncioFilter m = this.getModel();
        return dao.findByCarro(m.getCarro());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Page createFormPage(Anuncio entity, FormType formType) {
        return new CadastroAnuncio(this, new PageParameters(), entity, formType);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected AnuncioFilter createModel() {
        return new AnuncioFilter();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void addResultTableColumns(ReportTableBuilder<Anuncio> table) {
        table.addStringColumn("usuario", "Usuário", "usuario");
        table.addStringColumn("carro", "Carro", "carro");
        table.addStringColumn("link", "Link", new AbstractComponentValueResolver<Anuncio>() {

			public Component createComponents(String componentId, Anuncio value) {
				ExternalLink externalLink = new ExternalLink(componentId, value.getLink(), value.getLink());
				externalLink.setVisible(true);
				return externalLink;
			}

        });
    }


    /**
     * {@inheritDoc}
     */
    @Override
    protected MessageCreator getHelpTextCreator() {
        return null;
    }

	
}
